package io.sage.modules.socket.controller;

import javax.annotation.Resource;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import io.sage.common.utils.R;
import io.sage.modules.socket.service.SocketClientService;
import io.sage.modules.socket.service.SocketClientWeatherService;

/**
 * Created by Mafy on 2019/7/15.
 */
@RestController("SocketClientController")
public class SocketClientController implements Job{

    @Resource
    private SocketClientService socketClientService;
    
    @Resource
    private SocketClientWeatherService socketClient1Service;
    
    /**
     * 与串口服务器端口1获取数据
     * @param jsonObject
     * @return
     */
    @RequestMapping("/sendmsg")
    public R sendMsg(@RequestBody JSONObject jsonObject){
        String msg = jsonObject.getString("msg");
        socketClientService.sendMsg(msg);
        return R.ok();
    }
    
    /**
     * 与串口服务器端口2获取数据
     * @param jsonObject
     * @return
     */
    @RequestMapping("/sendmsg1")
    public R sendMsg1(@RequestBody JSONObject jsonObject){
    	String msg = jsonObject.getString("msg");
    	socketClient1Service.sendMsg(msg);
    	return R.ok();
    }

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
			/**
			 * 固定返回温湿度的字符串.
			 */
			String data="FF030001000DC011";
			socketClient1Service.sendMsg(data);
	}
    
    
}
